#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <openssl/rsa.h>
#include <openssl/rand.h>
#include <openssl/pem.h>
#include "../rsa/myRsa.h"
#include "sec_logger.h"

static int showFile(const char* filename)
{
	int c;
	FILE * in;
	
	if( ( in = fopen(filename,"rb") ) == NULL )
	{
		fprintf(stderr,"[Show]Error while openning log file.\n");
		return -1;	
	}
	while((c=fgetc(in))!=EOF)
	{
		fprintf(stdout, "%c", c);
	}
	return 1;
}

int
main(int argc, char** argv)
{
	char pwd[10];
	char* newfile;
	/*
	if((pwd=getpass("Pasword: "))==NULL)
		return 1;
	*/
	
	if((newfile=malloc(strlen(LOGFILE)+5))==NULL)
		return -1;
		
	sprintf(newfile,"%s.new",LOGFILE);
	
	/*sec_logAction("LOG1");
	sec_logAction("LOG2");
	sec_logAction("LOG3");*/
	//VER el caso de que el archivo no existe
		
	strcpy(pwd,"HOLA");
		
	//decrypt the file
	if( ( Twofish_dec(2, 128, SEC_LOGFILE, pwd))==-1)/*MODE_CBC*/
		return 1;

	//show in the screen
	showFile(newfile);
	remove(newfile);
	
	return 0;	
}

